package com.sky.controller.user;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrdersHistoryVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/order")
@Slf4j
@Api(tags = "C端-用户下单相关接口")
public class OrdersUserController {
    @Autowired
    private OrdersService ordersService;

    /**
     * 用户提交订单
     * @param ordersSubmitDTO
     * @return
     */
    @PostMapping("/submit")
    @ApiOperation("C端-用户提交订单接口")
    public Result<OrderSubmitVO> submit(@RequestBody OrdersSubmitDTO ordersSubmitDTO){
        OrderSubmitVO orderSubmitVO = ordersService.submit(ordersSubmitDTO);
        return Result.success(orderSubmitVO);
    }

    /**
     * 用户支付
     * @param ordersPaymentDTO
     * @return
     */
    @PutMapping("/payment")
    @ApiOperation("C端-模拟用户支付接口")
    public Result payment(OrdersPaymentDTO ordersPaymentDTO){
        /*
        * 此方法为模拟方法.模拟用户支付
        * 正常业务中需要根据订单号查询订单,
        * 然后把订单信息发送给微信端获得一个预订单,
        * 需要将预订单信息返回给前端
        */
        //这里支付之后要清空购物车
        ordersService.payment(ordersPaymentDTO);
        return Result.success();
    }

    /**
     * 查询历史订单
     * @param ordersPageQueryDTO
     * @return
     */
    @GetMapping("/historyOrders")
    @ApiOperation("C端-查询历史订单接口")
    public Result<PageResult> historyOrders(OrdersPageQueryDTO ordersPageQueryDTO){
        PageResult pageResult = ordersService.historyOrders(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 再来一单
     * @param id
     * @return
     */
    @PostMapping("/repetition/{id}")
    @ApiOperation("C端-再来一单接口")
    public Result repetition(@PathVariable Long id){
        ordersService.repetition(id);
        return Result.success();
    }

    /**
     * 查看订单详情
     * @param id
     * @return
     */
    @GetMapping("/orderDetail/{id}")
    @ApiOperation("C端-查看订单接口")
    public Result<OrdersHistoryVO> orderDetail(@PathVariable Long id){
        OrdersHistoryVO ordersHistoryVO = ordersService.orderDetail(id);
        return Result.success(ordersHistoryVO);
    }

    /**
     * 催单
     * @param id
     * @return
     */
    @GetMapping("/reminder/{id}")
    @ApiOperation("C端-催单接口")
    public Result reminder(@PathVariable Long id){
        ordersService.reminder(id);
        return Result.success();
    }

    /**
     * 取消订单
     * @param id
     * @return
     */
    @PutMapping("/cancel/{id}")
    @ApiOperation("C端-取消订单")
    public Result cancel(@PathVariable Long id){
        ordersService.cancel(id);
        return Result.success();
    }
}
